namespace Chaliy.Syndication.MediaRss
{
	using System;
	using System.Xml;
	using System.Xml.Schema;
	using System.Xml.Serialization;
    using System.Runtime.Serialization;

	/// <summary>
	/// 	Thumbnail allows particular images to be used as representative images for the media object.
	/// </summary>
	[XmlRoot("thumbnail", Namespace = Namespaces.MediaRssPrivate)]
    public sealed class MediaThumbnail : IXmlSerializable
    {
    	/// <summary>
    	/// 	Get or set the URL of the thumbnail. It is a required attribute.
    	/// </summary>
        public Uri Url
        {
            get;
            set;
        }
       
        /// <summary>
        /// 	Get or set the height of the thumbnail. It is an optional attribute.
        /// </summary>
        public int? Height
        {
            get;
            set;
        }

        /// <summary>
        /// 	Get or set the width of the thumbnail. It is an optional attribute.
        /// </summary>
        public int? Width
        {
            get;
            set;
        }

        #region IXmlSerializable Members

        XmlSchema IXmlSerializable.GetSchema()
        {
            throw new NotSupportedException(); // TODO Implement
        }

        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            throw new NotSupportedException(); // TODO Implement
        }

        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            ArgumentUtilities.EnsureArgumentNotNull(writer, "writer");

            if (this.Url == null)
            {
                SerializationException urlRequiredException
                    = new SerializationException(Resources.ThumbnailUrlRequired);

                urlRequiredException.Data["Attribute"] = "URL";
                urlRequiredException.Data["ReasonCode"] = "RequiredAttribute";

                throw urlRequiredException;
            }

            writer.WriteAttributeString("url", this.Url.ToString());
            
            writer.WriteInt32Attribute("height", this.Height);
            writer.WriteInt32Attribute("width", this.Width);
        }

        #endregion
    }

}
